﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Automobile.service.BLL;
using Automobile.service.Model;

namespace Automobile.service.UI
{
    public partial class Employee_list : System.Web.UI.Page
    {
        EmployeeBLL bll = new EmployeeBLL();
        int Pagesize = 10;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataSuouce();
            }
        }
        public void DataSuouce()
        {
            Repeater1.DataSource = bll.ShowlistEmployee(1, Pagesize);
            Repeater1.DataBind();
            Label1.Text = bll.EmpCount().ToString();
        }
        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            JournalBLL jbll = new JournalBLL();
            string ename = e.CommandName;//获取当前要执行的命令
            int id = Convert.ToInt32(e.CommandArgument);
            switch (ename)
            {
                case "uptstate":
                    if (Convert.ToInt32(bll.GetEmpStateById(id)) == 0)
                    {
                        if (bll.Updempstatefalse(id) > 0)
                        {
                            jbll.AddJourna_Updempstatefalse(Convert.ToInt32(Session["empid"]),id);
                            Response.Write("<script>alert('已停用')</script>");
                            DataSuouce();
                        }
                        else
                        {
                            Response.Write("<script>alert('服务器忙')</script>");
                            DataSuouce();
                        }
                    }
                    else
                    {
                        if (bll.Updempstatetrue(id) > 0)
                        {
                            jbll.AddJourna_Updempstatetrue(Convert.ToInt32(Session["empid"]), id);
                            Response.Write("<script>alert('已启用')</script>");
                            DataSuouce();
                        }
                        else
                        {
                            Response.Write("<script>alert('服务期忙')</script>");
                            DataSuouce();
                        }
                    }
                    break;
            }
        }
        protected void Unnamed_ServerClick(object sender, EventArgs e)
        {
            string Employee_Name = Request.Form["Employee_Name"].ToString();
            Repeater1.DataSource = bll.GetEmpByEmpName(Employee_Name,1,Pagesize);
            Repeater1.DataBind();
        }
    }
}